package com.hongxun.budget.ui.dialog;

import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.adapter.SpinnerAdapter;
import com.hongxun.budget.utils.DBUtils;
import com.hongxun.budget.utils.TestingUtils;
import com.hongxun.entity.LineName;
import com.hongxun.greenentity.tk.BDataDictionaryEntity;
import com.hongxun.interfaces.ResponseListener;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 线路台区
 */

public class LineNameDialog extends BaseCenterFragmentDialog {

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.spinner)
    Spinner spinner;
    @BindView(R.id.spinner2)
    Spinner spinner2;
    @BindView(R.id.content)
    EditText content;
    SpinnerAdapter<BDataDictionaryEntity> adapter1, adapter2;
    ResponseListener listener;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_linename;
    }

    @Override
    protected void initViews() {
        adapter1 = new SpinnerAdapter<BDataDictionaryEntity>(context, DBUtils.getBDataDictionaryEntities("range_type"), spinner);
        spinner.setAdapter(adapter1);
        adapter2 = new SpinnerAdapter<BDataDictionaryEntity>(context, DBUtils.getBDataDictionaryEntities("voltage_type"), spinner);
        spinner2.setAdapter(adapter2);
    }


    @OnClick(R.id.cancel)
    public void onViewClicked() {
        String result = content.getText().toString();
        if (!TestingUtils.isEmpty(context, result, "台区名称")) return;
        LineName lineName = new LineName(result, adapter1.getSelectedItem().getDKey(), adapter2.getSelectedItem().getDKey());
        if (listener != null) listener.response(lineName);
        dismiss();
    }

    public LineNameDialog setListener(ResponseListener listener) {
        this.listener = listener;
        return this;
    }
}
